﻿var $;
var $form;
var form;
layui.config({
	base : "js/"
}).use(['form','layer','jquery', 'upload'],function(){
	var layer = parent.layer === undefined ? layui.layer : parent.layer,
		laypage = layui.laypage;
		$ = layui.jquery;
		form = layui.form;
		var upload = layui.upload;
		
		

 	form.on("submit(addProductImg)",function(data){
 		//弹出loading
 		
 		var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
 		var msg;
 		$.ajax({
    		type: "post",
            url: ctx+"/productImg/insertProductImg",
            data:$("#auf").serialize(),
			dataType:"json",
			success:function(d){
				if(d.code==0){
		        	msg="添加成功！";
				}else{
		        	msg=d.msg;
				}
			}
        });
 		setTimeout(function(){
 			top.layer.close(index);
 			top.layer.msg(msg);
 			layer.closeAll("iframe");
 			//刷新父页面
	 		parent.location.reload();
        },2000);
 		return false;
 	})
 	
 	var uploadInst = upload.render({
		elem : '#product_img' //绑定元素
		,
		url :ctx+ '/UploadServlet?method=upload' //上传接口
		,
		done : function(res) {
			//上传完毕回调
			console.log(res);
			$("#photo").val('images/' + res.data);
			$("#imgFace").attr('src','/wk1un8/jsp/images/' + res.data);
		},
		error : function() {
			//请求异常回调
		}
	});
	
})
